<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function fn(n) {
            for (var a = 1; a <= n; a++) {
                if (a % 2 == 0) {
                    sum -= (1 / a)
                } else {
                    sum += (1 / a)
                }
            }
        }
        var n = prompt("求1~n个加减分数,请输入n")
        var sum = 0;
        fn(n);
        document.write(sum)
    </script>
</head>

<body>

</body>

</html>